﻿using System;
using System.Windows.Controls;
using System.Windows.Input;
using JurnalPembelian.ViewModels;

namespace JurnalPembelian
{
    public partial class FrmAdd : Page
    {
        public JurnalPembelianWrapViewModel WrapViewModel
        {
            get
            {
                return this.Resources["POW"] as JurnalPembelianWrapViewModel;
            }
        }

        public JurnalPembelianViewModel ViewModel
        {
            get
            {
                return this.DataContext as JurnalPembelianViewModel;
            }
        }

        public FrmAdd()
        {
            InitializeComponent();

            this.Loaded += (x, y) =>
            {
                (this.Resources["POW"] as JurnalPembelianWrapViewModel).JurnalPembelianViewModel =
                     (JurnalPembelianViewModel)this.DataContext;
                txtDate.Focus();
            };

            this.KeyDown += (o, e) =>
            {

                if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Control)
                    ViewModel.SaveJurnalPembelian(ViewModel.JurnalPembelian);
                else if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
                    ViewModel.Cancel(null);
            };
        }


        private void txtPrice_GotFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            (sender as TextBox).SelectAll();
        }

        private void textBox_GotFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            (sender as TextBox).SelectAll();
        }


        private void txtNoLog_GotFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            (sender as TextBox).SelectAll();
        }

    }
}

